home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / tl / tu-replace.el.z / tu-replace.el
Encoding:
Text File  |  1998-05-21  |  2.8 KB  |  85 lines

  1. ;;; tu-replace.el --- a replacing utility for GNU Emacs
  2.  
  3. ;; Copyright (C) 1995,1996 MORIOKA Tomohiko
  4.  
  5. ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
  6. ;; Version: $Id: tu-replace.el,v 3.0 1996/09/02 13:00:34 morioka Exp $
  7. ;; Keywords: replace
  8.  
  9. ;; This file is part of tl (Tiny Library).
  10.  
  11. ;; This program is free software; you can redistribute it and/or
  12. ;; modify it under the terms of the GNU General Public License as
  13. ;; published by the Free Software Foundation; either version 2, or (at
  14. ;; your option) any later version.
  15.  
  16. ;; This program is distributed in the hope that it will be useful, but
  17. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ;; General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with this program; see the file COPYING.  If not, write to
  23. ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. ;; Boston, MA 02111-1307, USA.
  25.  
  26. ;;; Commentary:
  27.  
  28. ;; - How to install.
  29. ;;   1. bytecompile this file and copy it to the apropriate directory.
  30. ;;   2. put the following lines to your ~/.emacs:
  31. ;;        (autoload 'edit-replace-region "tu-replace" nil t)
  32. ;; - How to use.
  33. ;;   1. mark in beginning of region you want to replace.
  34. ;;   2. go to end of region you want to replace.
  35. ;;   3. type M-x edit-replace-region [CR]
  36. ;;      then entering to ``edit-replace mode''.
  37. ;;   4. edit replacement string.
  38. ;;   5. type C-c C-c then specified region will be replaced.
  39.  
  40. ;;; Code:
  41.  
  42. (defvar edit-replace-mode-map nil)
  43. (if (null edit-replace-mode-map)
  44.     (progn
  45.       (setq edit-replace-mode-map (copy-keymap text-mode-map))
  46.       (define-key edit-replace-mode-map
  47.     "\C-c\C-c" (function edit-replace-query-replace))
  48.       ))
  49.  
  50. (make-variable-buffer-local 'edit-replace-original-buffer)
  51. (make-variable-buffer-local 'edit-replace-start-point)
  52. (make-variable-buffer-local 'edit-replace-end-point)
  53.  
  54. (defvar edit-replace-original-buffer nil)
  55. (defvar edit-replace-start-point nil)
  56. (defvar edit-replace-end-point nil)
  57.  
  58. (defun edit-replace-region (beg end &optional str)
  59.   (interactive "r")
  60.   (let ((the-buf (current-buffer))
  61.     (buf (get-buffer-create " *edit-replace*")))
  62.     (pop-to-buffer buf)
  63.     (setq major-mode 'edit-replace)
  64.     (setq mode-name "edit for replace")
  65.     (use-local-map edit-replace-mode-map)
  66.     (setq edit-replace-original-buffer the-buf)
  67.     (setq edit-replace-start-point beg)
  68.     (setq edit-replace-end-point end)
  69.     ))
  70.  
  71. (defun edit-replace-query-replace ()
  72.   (interactive)
  73.   (let ((beg edit-replace-start-point)
  74.     (end edit-replace-end-point)
  75.     str
  76.     (rstr (buffer-string))
  77.     )
  78.     (switch-to-buffer edit-replace-original-buffer)
  79.     (setq str (buffer-substring beg end))
  80.     (goto-char beg)
  81.     (query-replace str rstr)
  82.     ))
  83.  
  84. ;;; tu-replace.el ends here
  85.